<?php

require_once 'PHPUnit/Framework/TestCase.php';
require_once 'Inspekt.php';

        //$this->markTestIncomplete('not implemented');

class InspektCage_PostTest extends PHPUnit_Framework_TestCase {

    protected $fixture;

    public function setUp() {
        $ascii_str = '';
        for ( $i = 0; $i < 256; $i++ ) {
            $ascii_str .= chr($i);
        }
        $_POST = array(
            'ascii'   => $ascii_str,
            'dosdir1' => 'c:/x',
            'dosdir2' => 'c:/Temp/x',
            'dosdir3' => '/x',
            'localdir' => 'localdir',
            'rootdir1' => '/root',
            'rootdir2' => '/root/',
            'bindir'   => '/binary/dir' . chr(27) . 'name',
            'two'      => 2,
        );
        $this->fixture = Inspekt::makePostCage();
    }

    public function testPostInaccessible() {
        $this->assertNull($_POST);
    }

    public function testGetAlnum() {
        $this->assertEquals(
            '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
            $this->fixture->getAlnum('ascii') );
    }

    public function testGetAlpha() {
        $this->assertEquals(
            'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
            $this->fixture->getAlpha('ascii') );
    }

    public function testGetDigits() {
        $this->assertEquals( '0123456789', $this->fixture->getDigits('ascii') );
    }

    public function testGetDir() {
        if ( preg_match( '/windows/i', php_uname() ) ) {
            $this->assertEquals( 'c:\\', $this->fixture->getDir('dosdir1') );
            $this->assertEquals( 'c:/Temp', $this->fixture->getDir('dosdir2') );
            $this->assertEquals( '\\', $this->fixture->getDir('dosdir3') );
        }
        else {
            $this->assertEquals( '.', $this->fixture->getDir('localdir') );
            $this->assertEquals( '/', $this->fixture->getDir('rootdir1') );
            $this->assertEquals( '/', $this->fixture->getDir('rootdir2') );
            $this->assertEquals( '/binary', $this->fixture->getDir('bindir') );
        }
    }

}
